<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <base href="/">
    <link rel="stylesheet" href="../static/layui/css/layui.css">
    <script src="../static/js/jquery-3.2.1.min.js"></script>
    <script src="../static/layui/layui.js"></script>
    <script>
        $(function () {
            $("#btnClose").on("click", function () {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            });
            // 填充角色选项
            $.get({
                url: "admin/role/getAll"
                , success: function (result) {
                    if (result && result.success) {
                        var roles = result.data.list;
                        var roleIdsDiv = '';
                        for (var i = 0; i < roles.length; i++) {
                            var role = roles[i];
                            roleIdsDiv += '<option value="' + role.id + '">' + role.name + '</option>';
                        }
                        $("#roleIdsDiv").html(roleIdsDiv);
                        layui.form.render();
                    }else {
                        layer.msg(result.message);
                    }
                }
            });

            $("#save").on("click",function () {
                $.post({
                    url: "admin/account/create"
                    ,data: $("form").serialize()
                    ,success: function (result) {
                        if (result && result.success){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        }else {
                            layer.msg(result.message);
                        }
                    }
                })
            })
        });
    </script>
</head>
<body>
<div align="center">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-block">
                <input type="text" name="account" autocomplete="off" placeholder="账号会作为初始密码使用" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="email" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="phone" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-inline">
                <select name="roleId" id="roleIdsDiv">
                </select>
            </div>
        </div>
        <div class="layui-form-item model-form-footer" align="center">
            <!--<label class="layui-form-label"/></label>-->
            <button id="btnClose" class="layui-btn layui-btn-primary close" type="button">取消</button>
            <button class="layui-btn" lay-filter="userinfo-submit" lay-submit type="button" id="save">保存</button>
        </div>

    </form>
</div>
</body>
</html>